
import { getRole, setRole } from "@/utils/Auth"
import { getMenu, setMenu } from "@/utils/Routerinfo"
import { routes } from "@/router"
const state = {
    dymicRouter: getMenu() || [],
    role: getRole(),
}
const mutations = {
    SetDymic_router(state, { routers, rouinstace }) {
        routers.forEach(route => {
            route.component = () => import("@/layout")
            route.hello = () => "hello"
            route.children.forEach(rout => { rout.component = () => import(`@/views${rout.meta.url}`) })
        })
        const menuRoute = [...routes, ...routers];
        state.dymicRouter = menuRoute
        sessionStorage.setItem("menu", JSON.stringify(menuRoute))
        setMenu(menuRoute)
        menuRoute.forEach(route => {
            rouinstace.addRoute(route)
        })

    },
    // 设置用户角色
    setRole(state, role) {
        state.role = role;
        setRole(role)
    }
}

const actions = {
    setRole({ commit }, role) {
        commit("setRole", role)
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}